var express = require('express');
var router = express.Router();
var http = require('http').Server(express);
var io = require('socket.io')(http);

/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index');
});
io.on('connection', function (socket) {
    console.log('a user connected');
    socket.on("disconnect", function (obj) {
        io.emit("message", {msg:'某某某离开了聊天室'});
    });

    socket.on("message", function (obj) {
        io.emit("message", obj);
    });
});
http.listen(3001, function () {
    // 这个端口是给webscocket单独开的 好像必须给它单独开个端口
    console.log('listening on *:3001');
});
module.exports = router;
